package com.kartoshka.painters 
{
	import flash.display.Graphics;

	import com.kartoshka.interfaces.IPainter;
	import com.kartoshka.painters.NullPainter;

	/**
	 * @author Alexander Zats, 2009
	 */
	public class BlueprintPainter extends NullPainter implements IPainter
	{

		protected var _backgroundColor : uint;
		protected var _lineColor : uint;
		protected var _gridStep : uint;

		public function BlueprintPainter( backgroundColor : uint = 0x3182D9, lineColor : uint = 0xFFFFFF, gridStep : uint = 10 )
		{
			super( );
			
			this.backgroundColor = backgroundColor;
			this.lineColor = lineColor;
			this.gridStep = gridStep;
		}

		override public function draw(graphics : Graphics, width : Number, height : Number) : void
		{
			graphics.beginFill( _backgroundColor );
			_cornerRadius ? graphics.drawRoundRect( 0, 0, width, height, _cornerRadius, _cornerRadius ) : graphics.drawRect( 0, 0, width, height );
			graphics.endFill();
			
			for ( var x : int = 0; x < width ; x += 2 )
			{
				if ( x % ( _gridStep * 10 ) == 0 )
				{
					graphics.lineStyle( 0, _lineColor, 0.8 );
				}
				else
				{
					x % _gridStep ? graphics.lineStyle( 0, _lineColor, 0.1 ) : graphics.lineStyle( 0, _lineColor, 0.5 );
				} 
				
				graphics.moveTo( x, 0 );
				graphics.lineTo( x, height );
			}
			for ( var y : int = 0; y < height ; y += 2 )
			{
				if ( y % ( _gridStep * 10 ) == 0)
				{
					graphics.lineStyle( 0, _lineColor, 0.8 );
				}
				else
				{
					y % _gridStep ? graphics.lineStyle( 0, _lineColor, 0.1 ) : graphics.lineStyle( 0, _lineColor, 0.5 );
				} 

				graphics.moveTo( 0, y );
				graphics.lineTo( width, y );
			}
			graphics.lineStyle( 0, 0x000000, 0 );
		}

		public function set backgroundColor( value : uint ) : void
		{
			if ( value > 0xFFFFFF ) value = 0xFFFFFF;
			_backgroundColor = value;
		}

		public function get backgroundColor() : uint
		{
			return _backgroundColor;
		}

		public function set lineColor( value : uint ) : void
		{
			if ( value > 0xFFFFFF ) value = 0xFFFFFF;
			_lineColor = value;
		}

		public function get lineColor() : uint
		{
			return _lineColor;
		}

		public function set gridStep( value : uint ) : void
		{
			if ( value < 2 ) value = 2;
			_gridStep = value;
		}

		public function get gridStep() : uint
		{
			return _gridStep;
		}
	}
}
